package com.aier.school.action;

import java.sql.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.common.dao.ICommonDAO;
import com.aier.school.common.SchoolFinalPageSize;
import com.aier.school.entity.SchoolHoliday;
import com.aier.school.service.ISchoolHolidaysService;

@Scope("prototype")
@Component("schoolHolidaysManageAction")
public class SchoolHolidaysManageAction extends SchoolBaseAction {

    /**
     * 学校管理-管理员查看的假期管理  与  教师查看的假期管理
     */
    private static final long serialVersionUID = 1L;

    @Resource(name = "schoolHolidaysService")
    private ISchoolHolidaysService schoolHolidaysService;
    
    private int s;                //成功:1 ,失败:0
    private String error_info;    //错误提示信息

    private List<SchoolHoliday> scHolidays;        //学校假期列表
    
    private Integer sid;        //学校id
    private String txt_sdate;    //开始时间
    private String txt_edate;    //结束时间
    private Long hid;            //假期id
    private String describe;    //假期描述
    
    private int page;            //页数
    private int page_size;        //每页的记录数
    private int page_count;        //总页数
    private int count;            //总数


    @Override
    public String execute(){
        
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String search(){
        s = 0;
        if(page<=0){
            page=1;
        }
        Map<String,Object> map = schoolHolidaysService.searchscHolidaysByCondition(page,SchoolFinalPageSize.MONTH_ATTEND_LIST_PAGESIZE,
                sid,txt_sdate,txt_edate);
        if(null!=map){            
            scHolidays = (List<SchoolHoliday>) map.get(ICommonDAO.OBJ_LIST);
            if (null != scHolidays) {
                s = 1;
            }
            page = (Integer) map.get(ICommonDAO.PAGE);
            page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
            page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
            count = (Integer) map.get(ICommonDAO.COUNT);        
        } 
        return SUCCESS;
    }
    
    
    /**
     *  添加假期信息
     * @return
     */
    public String add() {
        try {
            Date sdate = Date.valueOf(txt_sdate);
            Date edate = Date.valueOf(txt_edate);
            s = schoolHolidaysService.insertSchoolHoliday(sdate, edate, sid,describe);    
        } catch (Exception e) {
            e.printStackTrace();
            s = 0;
        }
        return SUCCESS;
    }

    /**
     *  删除假期信息
     * @return
     */
    public String delete() {
        s = schoolHolidaysService.deleteSchoolHoliday(hid);
        return SUCCESS;
    }

    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public void setPage_count(int page_count) {
        this.page_count = page_count;
    }

    public int getS() {
        return s;
    }

    public String getError_info() {
        return error_info;
    }

    public List<SchoolHoliday> getScHolidays() {
        return scHolidays;
    }

    public int getCount() {
        return count;
    }

    public void setSchoolHolidaysService(
            ISchoolHolidaysService schoolHolidaysService) {
        this.schoolHolidaysService = schoolHolidaysService;
    }

    public void setTxt_sdate(String txt_sdate) {
        this.txt_sdate = txt_sdate;
    }

    public void setTxt_edate(String txt_edate) {
        this.txt_edate = txt_edate;
    }

    public void setHid(Long hid) {
        this.hid = hid;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    
}